$(function () {
    vm.getnumber();
    $("#jqGrid").jqGrid({
        url: baseURL + 'gaokaobaobei/zhaosheng/PerformanceAudit',
        datatype: "json",
        colModel: [
			{ label: '姓名', name: 'name', index: 'name', width: 60 },
			{ label: '考号', name: 'candidateNumber', index: 'candidate_number', width: 130},
			{ label: '文理属性', name: 'wlProperty', index: 'wl_property', width: 60 },
			{ label: '分数', name: 'score', index: 'score', width: 60 },
			{ label: '高中', name: 'highSchool', index: 'high_school', width: 100 },
			{ label: '联系电话', name: 'phone', index: 'phone', width: 80 }, 			
			{ label: '报备时间', name: 'creationDate', index: 'creation_date', width: 100 },
            { label: '备注', name: 'school', index: 'creation_date', width: 69 },
            { label: '状态', name: 'cz', index: 'cz', width: 80,
                formatter: function (data,a,rows) {
                   return `<button type="button" class="btn btn-success btn-xs" onclick="access(${rows.id},1)">通过</button><button type="button" class="btn btn-danger btn-xs" onclick="refuse(${rows.id},0)">拒绝</button>`
                } },
        ],
		viewrecords: true,
        height: 385,
        rowNum: 10,
		rowList : [10,30,50],
        rownumbers: true, 
        rownumWidth: 25, 
        autowidth:true,
        multiselect: true,
        pager: "#jqGridPager",
        jsonReader : {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames : {
            page:"page", 
            rows:"limit", 
            order: "order"
        },
        gridComplete:function(){
        	//隐藏grid底部滚动条
        	$("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" }); 
        }
    });
});

function refuse(data1,num)
{
    var str=prompt("拒绝原因","");
    if(str)
    {
        baobei(data1,num,str)
    }
}
function access(data1,num)
{
    var str = confirm("是否通过审核？",function () {
        baobei(data1,num,str)
    });
}

function baobei(data1,num,str) {
    if (num==0){
        var yuanyin = str;
        console.log(yuanyin);
       	if (yuanyin==null || yuanyin==""){
            alert("请注明拒绝原因！")
            return ;
        }
    }
    var data = "yuanyin="+yuanyin+"&num="+num+"&id="+data1;
    var url = "gaokaobaobei/zhaosheng/updateAgency";
    $.ajax({
        type: "POST",
        url: baseURL + url,
        data: data,
        success: function(r){
            if(r.flag){
                alert("审核成功~", function(index){
                    window.history.back()
                })

                alert("审核成功~")
                vm.reload();
                alert("审核成功~")
                window.history.back()
            } else {
                alert("审核失败了~")
            }
        }
    });
}

var vm = new Vue({
	el:'#rrapp',
	data:{
		showList: true,
		title: null,
		userBackup: {},
        number:"",
        type:null,
		msg : null
	},
	methods: {
        getnumber:function () {
            var url = "gaokaobaobei/agency/getNumber";
            $.ajax({
                type: "POST",
                url: baseURL + url,
                success: function(r){
                    vm.msg = r.msg;
                }
            });

        },
		query: function () {
			vm.reload();
		},
		add: function(){
			vm.showList = false;
			vm.title = "新增";
			vm.userBackup = {};
		},
		update: function (event) {
			var id = getSelectedRow();
			if(id == null){
				return ;
			}
			vm.showList = false;
            vm.title = "修改";
            
            vm.getInfo(id)
		},
		saveOrUpdate: function (event) {
			var url = vm.userBackup.id == null ? "gaokaobaobei/zhaosheng/save" : "gaokaobaobei/zhaosheng/update";
			$.ajax({
				type: "POST",
			    url: baseURL + url,
                contentType: "application/json",
			    data: JSON.stringify(vm.userBackup),
			    success: function(r){
			    	if(r.code === 0){
						alert('操作成功', function(index){
							vm.reload();
						});
					}else{
						alert(r.msg);
					}
				}
			});
		},
		del: function (event) {
			var ids = getSelectedRows();
			if(ids == null){
				return ;
			}
			
			confirm('确定要删除选中的记录？', function(){
				$.ajax({
					type: "POST",
				    url: baseURL + "gaokaobaobei/zhaosheng/delete",
                    contentType: "application/json",
				    data: JSON.stringify(ids),
				    success: function(r){
						if(r.code == 0){
							alert('操作成功', function(index){
								$("#jqGrid").trigger("reloadGrid");
							});
						}else{
							alert(r.msg);
						}
					}
				});
			});
		},
		getInfo: function(id){
			$.get(baseURL + "gaokaobaobei/zhaosheng/info/"+id, function(r){
                vm.userBackup = r.userBackup;
            });
		},
		reload: function (event) {
            vm.getnumber();
            vm.showList = true;
			var page = $("#jqGrid").jqGrid('getGridParam','page');
			$("#jqGrid").jqGrid('setGridParam',{
                postData:{'type': vm.type},
                page:page
            }).trigger("reloadGrid");
		}
	}
});